import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["organizationId", "type"],
    _excluded2 = ["organizationId"],
    _excluded3 = ["organizationId"];

/**
 * service - 站内消息
 * @date: 2018-8-10

 */
import request from 'utils/request';
import { CPAAS_MSG } from 'utils/config';
import { filterNullValueObject, parseParameters } from 'utils/utils';
/**
 *
 *查询站内消息
 * @export
 * @param {*} params
 * @returns
 */

export function queryMessage(_x) {
  return _queryMessage.apply(this, arguments);
}
/**
 *改变消息为未读
 *
 * @export
 * @param {*} params
 * @returns
 */

function _queryMessage() {
  _queryMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId, type, other, reqUrl, param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = params.organizationId, type = params.type, other = _objectWithoutProperties(params, _excluded);
            reqUrl = type === 'announce' ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/notices") : "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user");
            param = filterNullValueObject(parseParameters(other));

            if (type === 'notice') {
              param.userMessageTypeCode = 'NOTICE';
            }

            if (type === 'message') {
              param.userMessageTypeCode = 'MSG';
            }

            if (type === 'announce') {
              // param.receiverTypeCode = 'ANNOUNCE';
              // param.statusCode = 'PUBLISHED';
              param.userNotice = true;
              param.sort = 'publishedDate,DESC';
            }

            return _context.abrupt("return", request(reqUrl, {
              method: 'GET',
              query: param
            }));

          case 7:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryMessage.apply(this, arguments);
}

export function changeRead(_x2) {
  return _changeRead.apply(this, arguments);
}
/**
 *查询站内消息明细
 *
 * @export
 * @param {*} params
 * @returns
 */

function _changeRead() {
  _changeRead = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var organizationId, other;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            organizationId = params.organizationId, other = _objectWithoutProperties(params, _excluded2);
            return _context2.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/read-flag"), {
              method: 'POST',
              query: other
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _changeRead.apply(this, arguments);
}

export function queryMessageDetail(_x3) {
  return _queryMessageDetail.apply(this, arguments);
}
/**
 *删除站内消息
 *
 * @export
 * @param {*} params
 * @returns
 */

function _queryMessageDetail() {
  _queryMessageDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var organizationId, userMessageId, type, noticeId, reqUrl;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            organizationId = params.organizationId, userMessageId = params.userMessageId, type = params.type; // 公告 传递过来的 userMessageId 实际上是 noticeId

            noticeId = userMessageId;
            reqUrl = type === 'announce' ? "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/notices/user/").concat(noticeId) : "".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/").concat(userMessageId);
            return _context3.abrupt("return", request(reqUrl, {
              method: 'GET'
            }));

          case 4:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryMessageDetail.apply(this, arguments);
}

export function deleteMessage(_x4) {
  return _deleteMessage.apply(this, arguments);
}

function _deleteMessage() {
  _deleteMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var organizationId, other;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            organizationId = params.organizationId, other = _objectWithoutProperties(params, _excluded3);
            return _context4.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user"), {
              method: 'DELETE',
              query: other
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteMessage.apply(this, arguments);
}